package com.gancp.controller.BaseController;

import com.gancp.common.Constans;
import com.gancp.domain.User;
import org.apache.shiro.SecurityUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by GCP on 2018/5/3.
 * 基础的小逻辑
 */
public class BaseController {

    /**
     * @Author gancp
     * @Date 时间被黑洞吸走了
     * @Descripition 获取用户名称
     **/
    public String getUserName(HttpServletRequest request) {
        return getUser( request ).getUsername();
    }

    public Long getUserId(HttpServletRequest request) {
        return getUser( request ).getId();
    }

    public User getUser(HttpServletRequest request) {
       /* HttpSession session = request.getSession();
        User user = (User) session.getAttribute( Constans.USER_INFO );*/
        // 修改 从shiro中读取用户信息
        User user = (User) SecurityUtils.getSubject().getSession().getAttribute( Constans.USER_INFO );
        return user;
    }
}
